package com.my.screenadapter.myActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;


/**
 * Created by zyj 2019-1-3 13:49:27
 *  Function ：用于接受发出广播的反馈
 */
public class MatchReceiver extends BroadcastReceiver {
    private static final String MReceiveAction = "receiveMatch";
    private static BRInteraction brInteraction;
    private static final String TAG = "MatchReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        Log.w(TAG, "onReceive: ....." );
        if (brInteraction != null) {
            //TODO 用于自定义处理接收到的人脸识别信息
            Intent turnIntent = new Intent(context, IntentActivity.class);
            turnIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(turnIntent);
            brInteraction.setBundle(extras);
        }
    }

    public interface BRInteraction{
        public void setBundle (Bundle bundle);
    }

    public static void setBrInteractionListener(BRInteraction brInteraction) {
        MatchReceiver.brInteraction = brInteraction;
    }

    /**
     * 动态注册广播：
     */
    public static MatchReceiver registerMyReceiver(Context context) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(MReceiveAction);

        MatchReceiver receiver = new MatchReceiver();
        context.registerReceiver(receiver, filter);
        return receiver;
    }

}
